package com.example.lib_common.router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_common.mmkv.AuthMMKV

/**
 * @author yaotianxue
 * @description
 * @date 2024/10/23
 */
@Interceptor(priority = 8, name = "登陆拦截器")
class LoginAuthInterceptor:IInterceptor {
    override fun init(context: Context?) {

    }

    /**
     * 面切切面思想
     */
    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        val path = postcard?.path
        //要跳转的页面是否需要登陆判断
        if(path.equals("/live/LiveActivity")){//需要校验登陆
            if(!AuthMMKV.hasLogin()){
                //跳转到登陆页面
                callback?.onInterrupt(null)
                ARouter.getInstance().build( "/mine/LoginActivity").navigation()
            }
        }
        callback?.onContinue(postcard) //继续执行
    }
}